/*
Copyright (C) 2008-2010 Vana Development Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2
of the License.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#pragma once

#include "Player.h"

using std::string;

class Player;
class Item;

struct PlayerShopItem {
public:
	PlayerShopItem(Item *item, short bundles, int price) : item(item), bundles(bundles), price(price) { }

	void setBundles(short bundles) { this->bundles = bundles; }
	void setQuantity(short quantity) { this->quantity = quantity; }
	void setSlot(short slot) { this->slot = slot; }

	Item * getItem() const { return this->item; }
	short getBundles() { return this->bundles; }
	short getQuantity() const { return this->quantity; }
	short getSlot() const { return this->slot; }
	int getPrice() const { return this->price; }
private:
	Item *item;
	short bundles;
	short quantity;
	short slot;
	int price;
};

class PlayerShop {
public:
	PlayerShop(Player *player, int itemid, const string &description);

	void setOpen(bool open) { this->open = open; }

	void addItem(PlayerShopItem *item);
	void addVisitor(Player *player);
	void banPlayer(const string &name, char slot);
	void buyItem(Player *player, short slot, short quantity);
	void closeShop(bool sendtoplayer = true);
	void removeAllVisitors(char message);
	void removeItem(short slot);
	void removeVisitor(Player *player, bool sendtoplayer = true);
	void returnItem(short slot);
	void returnItems(bool sendtoplayer = true);
	void roomChat(Player *player, char slot, const string &chat);
	bool isBanned(string name);

	char getEmptyVisitorSlot();
	char getPlayerSlot(int id);
	Player * getOwner();
	Player * getVisitor(char slot);
	PlayerShopItem * getItem(short slot);

	bool isOwner(int id) { return (ownerid == id ? 1 : 0); }

	char getNumItems() { return (char)items.size(); }
	char getNumVisitors() { return (char)visitors.size(); }
	int getId() const { return this->id; }
	int getItemId() const { return this->itemid; }
	int getMap() const { return this->mapid; }
	int getOwnerId() const { return this->ownerid; }
	bool isOpen() const { return this->open; }
	string getDescription() const { return this->description; }
	string getOwnerName() const { return this->ownername; }
	Position getPos() const { return this->pos; }
private:
	int id;
	int itemid;
	int mapid;
	int ownerid;
	int itemsbought;
	bool open;
	string description;
	string ownername;
	Position pos;
	hash_map<string, int> banned;
	hash_map<int, Player *> visitors;
	hash_map<int, PlayerShopItem *> items;
};
